package parabullgame;

public class GuiControlButton extends GuiControlBase {
    boolean buttonDown;
    public GuiCallback callback;
    
    public GuiControlButton(int x,int y,int w,int h) {
        super(x,y,w,h);
        buttonDown = false;
    }
    
    public void draw(int offsetX, int offsetY) {
        DrawUtil.guiRect(offsetX,offsetY,width,height,color,buttonDown);
    }
    public void mouseClick(int button, boolean pressed, int x, int y) {
        if (button == 0) {
            if (pressed && !buttonDown) {
                buttonDown = true;
            }
            else if (!pressed && buttonDown) {
                buttonDown = false;
                if (callback != null) {callback.run();}
            }
        }
    }
    public void think(int mouseX, int mouseY) {
        if (buttonDown) {
            if (mouseX < 0 || mouseY < 0 || mouseX > width || mouseY > height) {
                buttonDown = false;
            }
        }
    }
}
